package com.yilijk.base.basedialog

import android.content.Context
import android.os.Bundle
import androidx.annotation.CallSuper
import androidx.appcompat.app.AlertDialog
import com.yilijk.base.R

/**
 * Created by SHICHENG
 *
 * Time on 2022/01/04
 *
 */
abstract class BaseDialog(context: Context): AlertDialog(context),DialogInterceptor {

    private var mChain: DialogChain? = null

    /*下一个拦截器*/
    fun chain(): DialogChain? = mChain

    @CallSuper
    override fun intercept(chain: DialogChain) {
        mChain = chain
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window?.setBackgroundDrawableResource(R.color.transparent)
    }

    fun setDialogWidth(width: Int? = 0){
        if (width!=0){
            window?.attributes?.width = width
        }
    }

    fun setDialogHeight(height: Int? = 0){
        if (height!=0){
            window?.attributes?.height = height
        }
    }

    fun setDialogWidth(size: Double? = 0.0){
        if (size!=0.0){
            window?.attributes?.width = (window?.attributes?.width!! * size!!).toInt()
        }
    }

    fun setDialogHeight(size: Double? = 0.0){
        if (size!=0.0){
            window?.attributes?.height = (window?.attributes?.height!! * size!!).toInt()
        }
    }


}